﻿package model.entity.product;

import java.util.Map;
import java.util.Map.Entry;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="Computer")
public class Computer extends Electronic {

	private String CPU;
	private String GPU;
	private String RAM;
	private String resolution;
	public String getCPU() {
		return CPU;
	}
	public void setCPU(String cPU) {
		CPU = cPU;
	}
	public String getGPU() {
		return GPU;
	}
	public void setGPU(String gPU) {
		GPU = gPU;
	}
	public String getRAM() {
		return RAM;
	}
	public void setRAM(String rAM) {
		RAM = rAM;
	}
	public String getResolution() {
		return resolution;
	}
	public void setResolution(String resolution) {
		this.resolution = resolution;
	}
	@Override
	public String toString() {
		return "Computer [CPU=" + CPU + ", GPU=" + GPU + ", RAM=" + RAM
				+ ", resolution=" + resolution + ", size=" + size
				+ ", warranty=" + warranty + ", powerCosume=" + powerCosume
				+ ", id=" + id + ", name=" + name + ", price=" + price
				+ ", image=" + image + ", quantity=" + quantity
				+ ", extraInfo=" + extraInfo + ", brand=" + brand + ", state="
				+ state + "]";
	}
	
	public static Map<String, Class<?>> fieldMap(){
		Map<String, Class<?>> fieldMap = Electronic.fieldMap();
		fieldMap.put("CPU", String.class);
		fieldMap.put("GPU", String.class);
		fieldMap.put("RAM", String.class);
		fieldMap.put("resolution", String.class);
		return fieldMap;
	}
	
	@Override
	public void insertData(Map<String, Object> valueMap) {
		super.insertData(valueMap);
		for (Entry<String, Object> entry : valueMap.entrySet()) {
			Object value = entry.getValue();
			
			//Dk rong
			if(entry.getValue() == null) continue;
			
			switch (entry.getKey()) {
			case "CPU":
				this.CPU = (String) value;
				break;
			case "GPU":
				this.GPU = (String) value;
				break;
			case "os":
				this.RAM = (String) value;
				break;
			case "threeG":
				this.resolution = (String) value;
				break;
			default:
				break;
			}
		}
	}
}

